package br.com.covosys.controller;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import br.com.covosys.exception.ApplicationException;
import br.com.covosys.model.LinkModel;
import br.com.covosys.model.ModelException;
import br.com.covosys.model.bean.Link;

@Scope("session")
@Controller
@SuppressWarnings("serial")
public class LinkController extends GenericController<Link, LinkModel> {
	
	@Autowired
	public LinkController(LinkModel linkModel) {
		super(linkModel);
		setBean(new Link());
		setList(new ArrayList<Link>());
	}
	
	public void saveOnList() throws ModelException, ApplicationException {
		boolean adicionar = true;
		for (Link link : getList()) {
			if (link == getBean()) {
				adicionar = false;
				break;
			}
		}
		if (adicionar) {
			getList().add(getBean());
		}
		cleanBean();
	}
	
	public void removeFromList() throws ModelException, ApplicationException {
		getList().remove(getBean());
		cleanBean();
	}
}
